<template>
  <div class="search-result">
    <div class="head">
      <div class="ift-back" @click="returns"></div>
      <h1>搜索结果</h1>
      <div></div>
    </div>
    <ul>
      <li v-for="(item, index) in image" :key="index" @click="details(item.id)">
        <img :src="item.OuterLayer" alt="" />
        <div class="Number-of-people">{{ item.names }}</div>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  data() {
    return {
      image: [],
    };
  },
  methods: {
    returns() {
      this.$router.push("/homePage");
    },
    details(id) {
      this.$router.push({ name: "details", query: { id: id } });
    },
  },
  created() {
    let name = this.$route.query.name;
    let image = this.$store.state.image;
    let index = image.findIndex((item) => item.names == name);
    this.image.push(image[index]);
    console.log(this.image);
  },
};
</script>
<style lang="less">
.search-result {
  .head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .cancel {
      font-size: 14px;
      color: black;
    }
    div {
      width: 60px;
      font-size: 20px;
      color: #fc6976;
      padding: 0 10px;
    }
    h1 {
      flex: 1;
      font-size: 18px;
      font-weight: 500;
      text-align: center;
    }
  }
  ul {
    li {
      float: left;
      margin: 0 0 5px 4%;
      width: 28%;
      text-align: center;
      img {
        width: 100%;
      }
      div {
        color: #555;
        font-size: 14px;
        width: 100%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>